/*
 * @Author: DUST
 * @Date: 2023-05-19 14:28:15
 * @LastEditors: DUST
 * @LastEditTime: 2023-06-17 19:50:42
 * @FilePath: \vite-project\src\views\browse\index\index.ts
 * @Description:
 * undefined
 */
import { siteHotsNews } from "@/api/forceEnd";
import { Ajax } from "@/interface";
import { message } from "ant-design-vue";
import { AxiosResponse } from "axios";
import { Ref, ref } from "vue";

export interface NewsData {
  baidu: Array<{ url: string; word: string, index: number; }>;
  weibo: Array<{ url: string; word: string, index: number; }>;
}
class Index {
  private _hotNews = ref<NewsData>();
  public get hotNews() : Ref<NewsData | undefined> {
    return this._hotNews;
  }
  
  /**
   * @description: 获取热点信息
   * @param {Array<string>} params: 热点类型
   */
  public gwtHotsNews = (params: Array<string>) => {
    siteHotsNews({ newsType: JSON.stringify(params) }).then((res: AxiosResponse<Ajax<NewsData>>) => {
      const data = res.data.data;
      this._hotNews.value = data;
    }).catch(err => {
      message.error(err.message);
    })
  }
  /**
   * @description: 刷新热点信息
   * @param {Array} params： 热点类型
   */  
  public reloadHotNews = (params: Array<string>) => {
    this._hotNews.value = undefined;
    this.gwtHotsNews(params);
  }
}

export default new Index();
